package com.tsingtree.modular.controller.view;

import com.tsingtree.base.auth.annotion.Permission;
import com.tsingtree.base.pojo.page.LayuiPageInfo;
import com.tsingtree.modular.entity.NanGiftFieldConfig;
import com.tsingtree.modular.model.params.NanGiftSubmissionParam;
import com.tsingtree.modular.service.NanGiftFieldConfigService;
import com.tsingtree.modular.service.NanGiftSubmissionService;
import com.tsingtree.roses.core.base.controller.BaseController;
import com.tsingtree.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 精美礼物-提交数据控制器
 *
 * @author jagger
 * @since 2025-10-24
 */
@Controller
@RequestMapping("/nanGiftSubmission")
public class NanGiftSubmissionController extends BaseController {

    private String PREFIX = "/nanGiftSubmission";

    @Autowired
    private NanGiftSubmissionService nanGiftSubmissionService;

    @Autowired
    private NanGiftFieldConfigService nanGiftFieldConfigService;

    /**
     * 跳转到主页面
     *
     * @author jagger
     */
    @RequestMapping("")
    public String index(@RequestParam(value = "activityId", required = false, defaultValue = "1") Integer activityId, Model model) {
        model.addAttribute("activityId", activityId);
        return PREFIX + "/nanGiftSubmission.html";
    }

    /**
     * 获取列表数据
     *
     * @author jagger
     */
    @RequestMapping("/list")
    @ResponseBody
    public LayuiPageInfo list(NanGiftSubmissionParam nanGiftSubmissionParam) {
        return this.nanGiftSubmissionService.findPageBySpec(nanGiftSubmissionParam);
    }

    /**
     * 获取字段配置
     *
     * @author jagger
     */
    @RequestMapping("/getFieldConfig")
    @ResponseBody
    public ResponseData getFieldConfig(@RequestParam("activityId") Integer activityId) {
        List<NanGiftFieldConfig> fieldConfigs = this.nanGiftFieldConfigService.getByActivityId(activityId);
        return ResponseData.success(fieldConfigs);
    }

    /**
     * 删除接口
     *
     * @author jagger
     */
    @RequestMapping("/delete")
    @Permission
    @ResponseBody
    public ResponseData delete(NanGiftSubmissionParam nanGiftSubmissionParam) {
        nanGiftSubmissionParam.setIsDel(true);
        this.nanGiftSubmissionService.update(nanGiftSubmissionParam);
        return ResponseData.success();
    }

}

